$(function () {
   var ue = UE.getEditor('editor',{
       'serverUrl':'/ueditor/upload/'
   });
   $('#add-post-btn').click(function (event) {
       event.preventDefault();
       var titleInput = $('input[name="title"]');
       var boardSelect = $('select[name="board_id"]');

       var title = titleInput.val();
       var content = ue.getContent();
       var board_id = boardSelect.val();

       if(!title || !content || !board_id){
           xtalert.alertInfoToast('请输入完整的帖子内容');
           return;
       }
       zlajax.post({
           'url':'/apost/',
           'data':{
               'title':title,
               'content':content,
               'board_id':board_id
           },
           'success':function (data) {
               if(data['code'] == 200){
                   xtalert.alertConfirm({
                       'title':'恭喜！帖子发布成功',
                       'confirmText':'再来一篇',
                       'cancelText':'返回首页',
                       'cancelCallback':function () {
                           window.location = '/';
                       },
                       'confirmCallback':function () {
                           titleInput.val("");
                           ue.setContent("")
                       }
                   })
               }else {
                   xtalert.alertInfo(data['message'])
               }
           }
       })


   })
});